/* List clicked View */
function getUserInfo(id){
	var url = "getUserInfo.jsp";
	var param = {
		work_no : id
	};
	callAjax(url,param, "USER_VIEW");
}

/* callAjax successAjax */
function successAjax(data, serviceName){
	if(serviceName == "USER_VIEW"){
		$('#system_name').val(data.rows[0].system_name);
		$('#system_id').val(data.rows[0].system_id);
		$('#system_kind').val(data.rows[0].system_kind);
		$('#os_version').val(data.rows[0].os_version);
		$('#sid').val(data.rows[0].sid);
		$('#ip_addr').val(data.rows[0].ip_addr);
		$('#connect_way').val(data.rows[0].connect_way);
		$('#connect_port').val(data.rows[0].connect_port);
		$('#data_req_res').val(data.rows[0].data_req_res);
		$('#req_res_port').val(data.rows[0].req_res_port);
		$('#admin_account').val(data.rows[0].admin_account);
		$('#system_desc').val(data.rows[0].system_desc);
		$('#create_date').val(data.rows[0].create_date);
	}
}

/* JqGrid User List */
function initGridUser() {
	$("#gridList").jqGrid({
		url:'getJqgridUserList.jsp',
		mtype: 'post',
		//postData: {  },
		datatype: "json",
		colNames:['사용자','이름','구분','시스템','ip주소','관리계정','접속방법'],
		colModel:[
				{name:'user_id',index:'user_id', width:50,align:"right",key:true},
				{name:'user_name',index:'user_name', width:80,align:"left"},
				{name:'type',index:'type', width:180,align:"left"},
				{name:"system",index:'system', width:100,align:"right"},
				{name:'ip_addr',index:'status', width:50,align:"right"},
				{name:'admin_account',index:'submit_date', width:50,align:"right"},
				{name:'connect_way',index:'submit_date', width:50,align:"right"}
			],
		rowList: [0,5,10,15,20],
		rowNum:5,
		height:240,
		autowidth : true,
		sortname: "user_id",
		sortorder: 'DESC',
		viewrecords: true,
		multiselect: true,//앞에 체크박스처리
		multikey: "",//multikey: "ctrlKey/shiftKey",
		pager: '#pager_id',
      
		onSelectRow: function(id){  //row가 선택되었을 경우
			getUserInfo(id);
		},
		loadComplete : function(data){
			pagecount = data.total;
			$("#pager").pager({ pagenumber: data.page, pagecount: pagecount, buttonClickCallback: PageClick });
        },
		loadError : function(xhr,st,err) {
			//jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
		},
		emptyrecords: "데이터가 존재하지 않습니다.",
		caption:'테이블',
		jsonReader: {
			repeatitems:false
		}
	});
	$("#gridList").jqGrid('navGrid','#pager_id',{edit:false,add:false,del:false,search:true});
}

/* JqGrid UserLog List */
function initGridUserLog() {
	$("#gridList2").jqGrid({
		url:'getJqgridUserLogList.jsp',
		mtype: 'post',
		//postData: {  },
		datatype: "json",
		colNames:['사용자','상태','구분','시스템명','신규','신청계정','사용기간','요청일시'],
		colModel:[
				{name:'user_id',index:'user_id', width:50,align:"right",key:true},
				{name:'status',index:'status', width:50,align:"left"},
				{name:'type',index:'type', width:50,align:"left"},
				{name:"system_name",index:'type', width:100,align:"right"},
				{name:'new_account',index:'new_account', width:50,align:"right"},
				{name:'join_account',index:'join_account', width:80,align:"right"},
				{name:'use_date',index:'use_date', width:150,align:"right"},
				{name:'request_time',index:'request_time', width:150,align:"right"}
			],
		rowList: [0,5,10,15,20],
		rowNum:5,
		height:130,
		autowidth : true,
		sortname: "user_id",
		sortorder: 'DESC',
		viewrecords: true,
		multiselect: false,//앞에 체크박스처리
		multikey: "",//multikey: "ctrlKey/shiftKey",
		pager: '#pager_id',
      
		onSelectRow: function(id){  //row가 선택되었을 경우
		},
		loadComplete : function(data){
			pagecount2 = data.total;
			$("#pager2").pager({ pagenumber: data.page, pagecount: pagecount2, buttonClickCallback: PageClick2 });
        },
		loadError : function(xhr,st,err) {
			//jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
		},
		emptyrecords: "데이터가 존재하지 않습니다.",
		caption:'테이블',
		jsonReader: {
			repeatitems:false
		}
	});
	$("#gridList2").jqGrid('navGrid','#pager_id',{edit:false,add:false,del:false,search:true});
}

var pagecount;
var pagecount2;

$(document).ready(function(){
	initGridUser();
	initGridUserLog();
});
PageClick = function(pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#gridList").setGridParam({ postData: { pagePlug: pageclickednumber} }).trigger("reloadGrid");  // Postdata을 넘겨주고 url로 지정된 ajax 호출하고 Grid을 Relo
}
PageClick2 = function(pageclickednumber) {
    $("#pager2").pager({ pagenumber: pageclickednumber, pagecount: pagecount2, buttonClickCallback: PageClick2 });
    $("#gridList2").setGridParam({ postData: { pagePlug: pageclickednumber} }).trigger("reloadGrid");  // Postdata을 넘겨주고 url로 지정된 ajax 호출하고 Grid을 Relo
}